package future;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

/**
 * @Author: deep as the sea
 * @Site: <a href="www.51doit.com">多易教育</a>
 * @QQ: 657270652
 * @Date: 2024/2/11
 * @Tips: 学大数据，到多易教育
 * @Desc:
 *  CompletableFuture 比  基础 Future强大之处： 异步任务的链式回调，以及多异步任务阶段之间的组合，汇聚等功能
 **/
public class Demo2 {

    public static void main(String[] args) throws InterruptedException, ExecutionException {

        CompletableFuture<String> cft = CompletableFuture.supplyAsync(() -> {
            System.out.println(Thread.currentThread().getName() + ", supply task 执行了");
            // 其他逻辑
            try {
                Thread.sleep(4000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }

            return "supply-result";
        });


        System.out.println("主线程工作之中……");
        System.out.println("主线程工作之中……");


        System.out.println(cft.get());



        Thread.sleep(Long.MAX_VALUE);
    }

}
